intro to ASM: l8 sizes to modulo
This level focuses on register manipulation. You'll modify and read from registers.
Values in memory will be set dynamically before each run, requiring formulaic operations with registers. We'll specify which registers are set and where to put the result (usually rax).
The div operator for modulo is slow, but we can optimize it.
A math trick optimizes the modulo operator (%). Compilers frequently use this.
For "x % y" where y is 2^n, the result is x's lower n bits.
We can efficiently implement modulo using lower register byte access.
Use only: mov
Compute:
rax = rdi % 256
rbx = rsi % 65536
Initial values:
rdi = 0xf71e
rsi = 0xc8f4d244
Provide assembly in bytes (max 0x1000 bytes):
SOL:

this image is going to help us.
256 = 2 ^ 8. therefore, we have to copy just the lower 8 bits of the register rdi to rax
65536 = 2^ 16. therefore we have to copy the lower 16 bits of the register rsi to rbx
now, the lower 8 bits of rdi (see pic) is DIL. and,
the lower 16 bits of rsi is SI.
so now, keeping the size in mind,
we move dil to al
and si to bx


